package com.example.apps

import com.example.lib_base.BaseViewModel
import com.example.lib_base.DownloadUtil.download
import com.example.lib_base.Res
import com.example.lib_base.UIIntent
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

@HiltViewModel
class AppsViewModel @Inject constructor(private val appsRepo: AppsRepo) : BaseViewModel<AppsIntent>() {
    override fun handleIntent(it: UIIntent) {
        when (it) {
            is AppsIntent.GetApps -> {
                httpRequest(appsRepo.getApps() as Flow<Res<Any>>)
            }
            is AppsIntent.DownloadApk -> {
                download(it.url, it.file)
            }


//            is AppsIntent.AddApp -> {
//                httpRequest(appsRepo.addApps(it.name))
//            }
        }
    }
}